// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   PmsResourceDaoImpl.java

package com.hfstu.pms.dataaccess.dao.impl;

import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.framework.core.orm.hibernate.PageDAOSpringTemplate;
import com.hfstu.framework.util.StringUtil;
import com.hfstu.pms.common.PmsCombinationType;
import com.hfstu.pms.dataaccess.dao.IPmsResourceDao;
import java.util.*;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class PmsResourceDaoImpl extends PageDAOSpringTemplate
	implements IPmsResourceDao
{

	public PmsResourceDaoImpl()
	{
	}

	public Page findPageByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		StringBuilder hql = new StringBuilder();
		hql.append("from PmsResource");
		return super.findPageByCondition(pageRequest, hql.toString(), filterPropertyMap, sortValueMap);
	}

	private DetachedCriteria defaultCriteria()
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass(), "pmsResource");
		return criteria;
	}

	public List findListByCondition(Map filterPropertyMap, Map sortValueMap)
	{
		DetachedCriteria criteria = defaultCriteria();
		if (filterPropertyMap != null && !filterPropertyMap.isEmpty())
		{
			Object value = null;
			Set keys = filterPropertyMap.keySet();
			for (Iterator iterator = keys.iterator(); iterator.hasNext();)
			{
				String key = (String)iterator.next();
				value = filterPropertyMap.get(key);
				if (key.equals("pmsResource.combinationType") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("pmsResource.systemCode") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("pmsResource.menuId") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("pmsResource.nodeId") && !StringUtil.isNullOrEmpty((String)value))
					criteria.add(Restrictions.eq(key, value));
				if (key.equals("pmsResource.nodeIds"))
					criteria.add(Restrictions.in("pmsResource.nodeId", (Object[])value));
				value = null;
			}

		}
		return super.findListByCriteria(criteria);
	}

	public void saveLists(List pmsResource)
	{
		super.saveEntities(pmsResource);
	}

	public void deleteResourceById(String roleId, String systemCode)
	{
		StringBuffer hql = new StringBuffer();
		hql.append(" delete from PmsResource pmsResource");
		hql.append((new StringBuilder(" where pmsResource.combinationType ='")).append(PmsCombinationType.ROLE_RESOURCE.getKey()).append("'").toString());
		hql.append((new StringBuilder(" and pmsResource.nodeId='")).append(roleId).append("'").toString());
		hql.append((new StringBuilder(" and pmsResource.systemCode='")).append(systemCode).append("'").toString());
		super.executeUpdate(hql.toString());
	}
}
